<template>
	<div>
		<h2 class="public-title">代理分享</h2>
		<div class="dl-share clearfix">
			<Spin fix size="large" v-if="loading"></Spin>
			<div class="share-box fl" v-if="reg_swicth.reg_xiaxian == 1">
				<div class="share-title">注册成为下线</div>
				<!-- <img :src="codeUrlxiaxian" alt=""> -->
				<span class="qrcode-wrapper" id="qrcode" ref="qrcode"></span>
				<p class="copy-title">邀请链接</p>
				<textarea class="link-box" v-model="jumpUrlxiaxian" readonly id="textUrl"  style="resize:none;height:85px"></textarea>
				<button class="gold-btn" @click="copyUnderLineUrl">复制链接</button>
			</div>
			<div class="share-box fl" v-if="reg_swicth.reg_caijin == 1">
				<div class="share-title">注册充值送彩金</div>
				<!-- <img :src="codeUrlcaijin" alt=""> -->
				<span class="qrcode-wrapper" id="qrcode2" ref="qrcode2"></span>
				<p class="copy-title">邀请链接</p>
				<textarea class="link-box" v-model="jumpUrlcaijin" readonly id="text"  style="resize:none;height:85px"></textarea>
				<button class="gold-btn" @click="copyUrl">复制链接</button>
			</div>
		</div>
	</div>
</template>
  
<script>
import { jsonToString } from "@/common/js/jsonToString";
import QRCode from 'qrcodejs2'
export default {
	data() {
		return {
			loading: false,
			reg_swicth: {},
			jumpUrlxiaxian: "",
			jumpUrlcaijin: "",

			h5Link: '',
			codeUrlxiaxian: '',
			codeUrlcaijin: '',
		};
	},
	created() {
		this._getAgencyShare();
		// this.getShareData();
	},
	mounted () {
		
	},
	methods: {
		getShareData() {
			var params = {
				token: localStorage.getItem("token")
			};
			this.loading = true;
			this.$http.post(this.urlRequest + "?m=api&c=app&a=getShortLink", params).then(res => {
				this.loading = false;
				if (res.data.status == 0) {
					this.reg_swicth = res.data.data.reg_swicth;
					this.codeUrlxiaxian = this.urlRequest + "?m=api&c=user&a=QRcode" + "&type=2" + "&token=" + localStorage.getItem("token");
					this.codeUrlcaijin = this.urlRequest + "?m=api&c=user&a=QRcode" + "&type=3" + "&token=" + localStorage.getItem("token");
					this.jumpUrlxiaxian = res.data.data.pc.offline;
					this.jumpUrlcaijin = res.data.data.pc.money;
					this.h5Link = res.data.data.app;
				}
			}).catch(error => {
				this.loading = false;
				this.$Message.error("数据请求超时");
			});
		},
		_getAgencyShare: function() {
			var params = {
				token: localStorage.getItem("token")
			};
			this.loading = true;
			this.$http.post(this.urlRequest + "?m=api&c=user&a=agentSharing", params).then(res => {
				this.loading = false;
				if (res.data.status == 0) {
					this.reg_swicth = res.data.reg_swicth;
					this.jumpUrlxiaxian = this.imgRequest + res.data.JumpUrl + '&type=2';
					this.jumpUrlcaijin = this.imgRequest + res.data.JumpUrl + '&type=3';

					this.$nextTick(() => {
						this.qrcode(this.jumpUrlxiaxian, this.jumpUrlcaijin);
					})
				}
			}).catch(error => {
				this.loading = false;
				this.$Message.error("数据请求超时");
			});
		},
		qrcode(Url1, Url2) {
			let qrcode = new QRCode('qrcode', {  
				width: 168,  // 设置宽度 
				height: 168, // 设置高度
				text: Url1
			})
			let qrcode2 = new QRCode('qrcode2', {  
				width: 168,  // 设置宽度 
				height: 168, // 设置高度
				text: Url2
			})
		},
		//点击复制功能
		copyUrl: function() {
			var ele = document.getElementById("text");
			ele.select();
			document.execCommand("Copy");
			this.$Message.success("复制成功");
		},
		copyUnderLineUrl: function() {
			var ele = document.getElementById("textUrl");
			ele.select();
			document.execCommand("Copy");
			this.$Message.success("复制成功");
		}
	},
	watch: {
		
	}
};
</script>
<style scoped>
.gold-btn {
  	border: 0;
}
.pc-cont {
  	padding-top: 0px;
}
.dl-share {
	position: relative;
	min-height: 300px;
}
.qrcode-wrapper {
	display: inline-block;
	width: 168px;
	height: 168px;
}
</style>




// WEBPACK FOOTER //
// src/components/PersonalCenter/agencyShare/agencyShare.vue